
let cartlist = localStorage.getItem("cartlist");
try {
  cartlist = JSON.parse(cartlist) || []
} catch (err) {
  cartlist = []
}

function updateStorage(key, data) {
  if (typeof data === "object") {
    data = JSON.stringify(data);
  }
  localStorage.setItem(key, data);
}

export default {
  namespaced: true,
  state: {
    cartlist,
  },
  getters: {
    totalPrice() {},
  },
  mutations: {
    // addTocart(state, payload) {
    //   state.cartlist.unshift(payload);
    //   updateStorage("cartlist", state.cartlist);
    // },
    //   removeFromCart(state, ids) {
    //     state.cartlist = state.cartlist.filter((item) => {
    //         return !ids.includes(item.goods_id);
    //     });
    //     updateStorage("cartlist", state.cartlist);
    //   },
    },
    
};